using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Decisions.HL7.Message;
using DecisionsFramework;

namespace Decisions.HL7.Message
{
    public class AddressTypeAttribute:RuleAttribute
    {
        private Dictionary<HL7Version, string[]> validVersionCodes = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, string[]> validVersionDescriptions = new Dictionary<HL7Version, string[]>();
        private Dictionary<HL7Version, HL7TableType> tableVersionTypes = new Dictionary<HL7Version, HL7TableType>();

        public AddressTypeAttribute()
        {
            // init the values for table version types
						tableVersionTypes[HL7Version.v23] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v231] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v24] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v25] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v251] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v26] = HL7TableType.HL7;
						tableVersionTypes[HL7Version.v27] = HL7TableType.HL7;
			
            
			// init the values for version codes
						validVersionCodes[HL7Version.v23] = new string[]{"B","C","F","H","M","O","P"};
						validVersionCodes[HL7Version.v231] = new string[]{"C","P","M","B","O","H","N","BDL","BR","F","L","RH","BA"};
						validVersionCodes[HL7Version.v24] = new string[]{"BA","N","BDL","F","C","B","H","L","M","O","P","RH","BR"};
						validVersionCodes[HL7Version.v25] = new string[]{"BA","N","BDL","F","C","B","H","L","M","O","P","RH","BR"};
						validVersionCodes[HL7Version.v251] = new string[]{"BA","N","BDL","F","C","B","H","L","M","O","P","RH","BR"};
						validVersionCodes[HL7Version.v26] = new string[]{"BA","BI","N","BDL","F","C","B","H","L","M","O","P","RH","BR","S","SH","V"};
						validVersionCodes[HL7Version.v27] = new string[]{"BA","BI","N","BDL","F","C","B","H","L","M","O","P","RH","BR","S","SH","TM","V"};
			
			// init the values for version descriptions
						validVersionDescriptions[HL7Version.v23] = new string[]{"Business","Current or Temporary","County of Origin","Home","Mailing","Office","Permanent"};
						validVersionDescriptions[HL7Version.v231] = new string[]{"Current Or Temporary","Permanent","Mailing","Firm/Business","Office","Home","Birth (nee) (birth address, not otherwise specified)","Birth delivery location (address where birth occurred)","Residence  at birth (home address at time of birth)","Country Of Origin","Legal Address","Registry home.  Refers to the information system, typically managed by a public health agency, that  stores patient information such as immunization histories or cancer data, regardless of where the patient obtains services.","Bad address"};
						validVersionDescriptions[HL7Version.v24] = new string[]{"Bad address","Birth (nee) (birth address, not otherwise specified)","Birth delivery location (address where birth occurred)","Country Of Origin","Current Or Temporary","Firm/Business","Home","Legal Address","Mailing","Office","Permanent","Registry home.  Refers to the information system, typically managed by a public health agency, that stores patient information such as immunization histories or cancer data, regardless of where the patient obtains services.","Residence  at birth (home address at time of birth)"};
						validVersionDescriptions[HL7Version.v25] = new string[]{"Bad address","Birth (nee) (birth address, not otherwise specified)","Birth delivery location (address where birth occurred)","Country Of Origin","Current Or Temporary","Firm/Business","Home","Legal Address","Mailing","Office","Permanent","Registry home. Refers to the information system, typically managed by a public health agency, that stores patient information such as immunization histories or cancer data, regardless of where the patient obtains services.","Residence at birth (home address at time of birth)"};
						validVersionDescriptions[HL7Version.v251] = new string[]{"Bad address","Birth (nee) (birth address, not otherwise specified)","Birth delivery location (address where birth occurred)","Country Of Origin","Current Or Temporary","Firm/Business","Home","Legal Address","Mailing","Office","Permanent","Registry home. Refers to the information system, typically managed by a public health agency, that stores patient information such as immunization histories or cancer data, regardless of where the patient obtains services.","Residence at birth (home address at time of birth)"};
						validVersionDescriptions[HL7Version.v26] = new string[]{"Bad address","Billing Address","Birth (nee)  (birth address, not otherwise specified)","Birth delivery location  (address where birth occurred)","Country Of Origin","Current Or Temporary","Firm/Business","Home","Legal Address","Mailing","Office/Business","Permanent","Registry home. Refers to the information system, typically managed by a public health agency, that stores patient information such as immunization histories or cancer data, regardless of where the patient obtains services.","Residence at birth (home address at time of birth)","Service Location","Shipping Address","Vacation"};
						validVersionDescriptions[HL7Version.v27] = new string[]{"Bad address","Billing Address","Birth (nee)  (birth address, not otherwise specified)","Birth delivery location  (address where birth occurred)","Country Of Origin","Current Or Temporary","Firm/Business","Home","Legal Address","Mailing","Office/Business","Permanent","Registry home. Refers to the information system, typically managed by a public health agency, that stores patient information such as immunization histories or cancer data, regardless of where the patient obtains services.","Residence at birth (home address at time of birth)","Service Location","Shipping Address","Tube Address","Vacation"};
			            

        }

        
        public override ValidationIssue[] RunRule(string name, object owningObject, object value)
        {
            //todo: check if the value is valid in the current version
            //if the value is not valid in the current version, add it as a validation issue


            return new ValidationIssue[0];
        }
    }
}
